/*
 * Copyright 2015-2016 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.webull.information.center.carwler.common.model;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.webull.framework.util.UtilJson;

/**
 * 档案关系对象
 *
 * @author <a href="mailto:yh@ustockex.com">杨浩</a>
 * @since 0.1.0
 */
public class ArchiveRel implements Serializable {
	/**
	 * @Fields serialVersionUID : TODO
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * webull档案类型
	 */
	private Integer type;
	/**
	 * webull档案id
	 */
	private Integer wlId;
	/**
	 * 通联档案id
	 */
	private String tlId;
	/**
	 * 晨星档案id
	 */
	private String msId;
	/**
	 * 路透id
	 */
	private String rtId;
	private String msCnId;
	private String usMsId;// 中国基金的usid
	private String rtRicId;
	private String rtDataRic; // 取行情数据用的RIC
	private String rtNricId;
	private String rtChainId; // 取指数成分股链代码
	private String atId;
	/**
	 * 恒生id
	 */
	private String hsId;
	/**
	 * 内存数据
	 */
	private Map<String, Object> datas = new HashMap<>();

	public ArchiveRel() {
	}

	public ArchiveRel(Integer type, Integer wlId, String tlId) {
		this.type = type;
		this.wlId = wlId;
		this.tlId = tlId;
	}

	public String getRtDataRic() {
		return rtDataRic;
	}

	public void setRtDataRic(String rtDataRic) {
		this.rtDataRic = rtDataRic;
	}

	public String getRtNricId() {
		return rtNricId;
	}

	public void setRtNricId(String rtNricId) {
		this.rtNricId = rtNricId;
	}

	public String getRtChainId() {
		return rtChainId;
	}

	public String getUsMsId() {
		return usMsId;
	}

	public void setUsMsId(String usMsId) {
		this.usMsId = usMsId;
	}

	public void setRtChainId(String rtChainId) {
		this.rtChainId = rtChainId;
	}

	public String getRtRicId() {
		return rtRicId;
	}

	public void setRtRicId(String rtRicId) {
		this.rtRicId = rtRicId;
	}

	/**
	 * @return {@link #type}
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * @param type
	 *            {@link #type}
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * @return {@link #wlId}
	 */
	public Integer getWlId() {
		return wlId;
	}

	/**
	 * @param wlId
	 *            {@link #wlId}
	 */
	public void setWlId(Integer wlId) {
		this.wlId = wlId;
	}

	/**
	 * @return {@link #tlId}
	 */
	public String getTlId() {
		return tlId;
	}

	/**
	 * @param tlId
	 *            {@link #tlId}
	 */
	public void setTlId(String tlId) {
		this.tlId = tlId;
	}

	/**
	 * @return {@link #datas}
	 */
	public Map<String, Object> getDatas() {
		return datas;
	}

	/**
	 * @param datas
	 *            {@link #datas}
	 */
	public void setDatas(Map<String, Object> datas) {
		this.datas = datas;
	}

	public String getMsId() {
		return msId;
	}

	public void setMsId(String msId) {
		this.msId = msId;
	}

	public String getMsCnId() {
		return msCnId;
	}

	public void setMsCnId(String msCnId) {
		this.msCnId = msCnId;
	}

	public String getRtId() {
		return rtId;
	}

	public void setRtId(String rtId) {
		this.rtId = rtId;
	}

	public String getHsId() {
		return hsId;
	}

	public void setHsId(String hsId) {
		this.hsId = hsId;
	}
	
	public String getAtId() {
		return atId;
	}

	public void setAtId(String atId) {
		this.atId = atId;
	}

	@Override
	public String toString() {
		return getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()) + UtilJson.writeValueAsString(this);
	}

	public static final class Type {
		// 1000：交易所，1100：板块, 1 指数 2 为股票 3 为基金 4 为期货 5 为债券，6 为外汇, 7期权
		public static final Integer exchange = 1000, group = 1100, index = 1, stock = 2, fund = 3, futures = 4, bond = 5, foreginExchange = 6, opt = 7,
				company = 2000;

		/**
		 * @param assetClass
		 *            E 股票,B 债券,F 基金,IDX 指数,FU 期货,OP 期权
		 * @return
		 */
		public static Integer getTypeByTlAssetClass(String assetClass) {
			if ("E".equals(assetClass)) {
				return stock;
			}
			if ("B".equals(assetClass)) {
				return bond;
			}
			if ("F".equals(assetClass)) {
				return fund;
			}
			if ("IDX".equals(assetClass)) {
				return index;
			}
			if ("FU".equals(assetClass)) {
				return futures;
			}
			if ("OP".equals(assetClass)) {
				return opt;
			}
			throw new IllegalArgumentException("assetClass=" + assetClass);
		}
	}

	public static final class Src {
		private static final Set<String> srcKeys = new HashSet<>();
		public static final String tl = "tl";
		public static final String ms = "ms";
		public static final String rt = "rt";
		public static final String ms_cn = "ms_cn";
		public static final String us_ms = "us_ms";
		public static final String rt_ric = "rt_ric";
		public static final String rt_data_ric = "rt_data_ric";
		public static final String rt_nric = "rt_nric";
		public static final String hs = "hs";
		public static final String rt_chain = "rt_chain";
		public static final String at = "at";
		static {
			srcKeys.add(tl);
			srcKeys.add(ms);
			srcKeys.add(ms_cn);
			srcKeys.add(us_ms);
			srcKeys.add(rt);
			srcKeys.add(rt_ric);
			srcKeys.add(rt_data_ric);
			srcKeys.add(rt_nric);
			srcKeys.add(hs);
			srcKeys.add(rt_chain);
			srcKeys.add(at);
		}

		public static void checkSrc(String src) {
			if (!srcKeys.contains(src)) {
				throw new IllegalArgumentException("src=" + src);
			}
		}
	}
}
